import React from "react"
import {
  View,
  Text,
  TouchableNativeFeedback
} from 'react-native'
import { connect } from 'react-redux';
import PropTypes from 'prop-types';

import UserService from '@/services/UserService'
import NavigationService from '@/services/NavigationService'


class HomeScreen extends React.Component {

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    if(!this.props.isLoggedIn) {
      setTimeout(()=>{
      NavigationService.navigate('Login')

      }, 200)
    }
  }

  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
        <TouchableNativeFeedback
            onPress={()=>{
              NavigationService.navigate('Test',{name: 'wangjiang'})
              UserService.setUserName("wangjiang")
            }}
          >
          <View style={{width: 150, height: 100, backgroundColor: 'red'}}>
            <Text style={{margin: 30}}>Button</Text>
          </View>
        </TouchableNativeFeedback>
        <Text>{ this.props.name }</Text>
      </View>
    );
  }
}

const mapStateToProps = state => ({
  isLoggedIn: state.auth.isLoggedIn,
  name: state.auth.name,
});

export default connect(mapStateToProps)(HomeScreen);
